package com.daxt.controller.fileuse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.daxt.common.result.PageInfo;
import com.daxt.common.result.PageUtil;
import com.daxt.common.result.Result;
import com.daxt.common.result.ResultCode;
import com.daxt.common.result.ResultUtil;
import com.daxt.mapper.use.UseUserRecordLogMapper;
import com.daxt.model.service.use.param.UseQuery;
import com.daxt.model.service.use.vo.UseUserRecordLog;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@Api(tags = "档案利用")
@RestController
@RequestMapping("/fileUseManager")
public class UseRecordController {
	
	@Autowired
	private UseUserRecordLogMapper useUserRecordLogMapper;
	
	@ApiOperation(value = "利用记录", notes = "") 
	@PostMapping("/useRecord") 
	public Result<PageInfo<UseUserRecordLog>> useRecord(@RequestBody UseQuery useQuery){
		Page<UseUserRecordLog> page=new Page<>(useQuery.getPageNum()==null?0:useQuery.getPageNum(), useQuery.getPageSize()==null?10:useQuery.getPageSize());
		QueryWrapper<UseUserRecordLog> queryWrapper=new QueryWrapper<>();
		if(!StringUtils.isEmpty(useQuery.getTitle())) {
		queryWrapper.eq("title", useQuery.getTitle());
		}
		
		if(useQuery.getStartTime()!=null&&useQuery.getEndTime()!=null) {
			queryWrapper.between("createTime", useQuery.getStartTime(), useQuery.getEndTime());
		}
		
		IPage<UseUserRecordLog> info = useUserRecordLogMapper.selectPage(page, queryWrapper);
		PageInfo<UseUserRecordLog> data = PageUtil.data(info.getPages(), info.getCurrent(), info.getTotal(), info.getRecords());
		return ResultUtil.data(ResultCode.RESULT_SUCCESS.getCode(),"", data);
	}
	
	
}
